// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class TrainedModelTree
{
	[JsonInclude, JsonPropertyName("classification_labels")]
	public ICollection<string>? ClassificationLabels { get; set; }
	[JsonInclude, JsonPropertyName("feature_names")]
	public ICollection<string> FeatureNames { get; set; }
	[JsonInclude, JsonPropertyName("target_type")]
	public string? TargetType { get; set; }
	[JsonInclude, JsonPropertyName("tree_structure")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNode> TreeStructure { get; set; }
}

public sealed partial class TrainedModelTreeDescriptor : SerializableDescriptor<TrainedModelTreeDescriptor>
{
	internal TrainedModelTreeDescriptor(Action<TrainedModelTreeDescriptor> configure) => configure.Invoke(this);

	public TrainedModelTreeDescriptor() : base()
	{
	}

	private ICollection<string>? ClassificationLabelsValue { get; set; }
	private ICollection<string> FeatureNamesValue { get; set; }
	private string? TargetTypeValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNode> TreeStructureValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor TreeStructureDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor> TreeStructureDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor>[] TreeStructureDescriptorActions { get; set; }

	public TrainedModelTreeDescriptor ClassificationLabels(ICollection<string>? classificationLabels)
	{
		ClassificationLabelsValue = classificationLabels;
		return Self;
	}

	public TrainedModelTreeDescriptor FeatureNames(ICollection<string> featureNames)
	{
		FeatureNamesValue = featureNames;
		return Self;
	}

	public TrainedModelTreeDescriptor TargetType(string? targetType)
	{
		TargetTypeValue = targetType;
		return Self;
	}

	public TrainedModelTreeDescriptor TreeStructure(ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNode> treeStructure)
	{
		TreeStructureDescriptor = null;
		TreeStructureDescriptorAction = null;
		TreeStructureDescriptorActions = null;
		TreeStructureValue = treeStructure;
		return Self;
	}

	public TrainedModelTreeDescriptor TreeStructure(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor descriptor)
	{
		TreeStructureValue = null;
		TreeStructureDescriptorAction = null;
		TreeStructureDescriptorActions = null;
		TreeStructureDescriptor = descriptor;
		return Self;
	}

	public TrainedModelTreeDescriptor TreeStructure(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor> configure)
	{
		TreeStructureValue = null;
		TreeStructureDescriptor = null;
		TreeStructureDescriptorActions = null;
		TreeStructureDescriptorAction = configure;
		return Self;
	}

	public TrainedModelTreeDescriptor TreeStructure(params Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor>[] configure)
	{
		TreeStructureValue = null;
		TreeStructureDescriptor = null;
		TreeStructureDescriptorAction = null;
		TreeStructureDescriptorActions = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ClassificationLabelsValue is not null)
		{
			writer.WritePropertyName("classification_labels");
			JsonSerializer.Serialize(writer, ClassificationLabelsValue, options);
		}

		writer.WritePropertyName("feature_names");
		JsonSerializer.Serialize(writer, FeatureNamesValue, options);
		if (!string.IsNullOrEmpty(TargetTypeValue))
		{
			writer.WritePropertyName("target_type");
			writer.WriteStringValue(TargetTypeValue);
		}

		if (TreeStructureDescriptor is not null)
		{
			writer.WritePropertyName("tree_structure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, TreeStructureDescriptor, options);
			writer.WriteEndArray();
		}
		else if (TreeStructureDescriptorAction is not null)
		{
			writer.WritePropertyName("tree_structure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor(TreeStructureDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (TreeStructureDescriptorActions is not null)
		{
			writer.WritePropertyName("tree_structure");
			writer.WriteStartArray();
			foreach (var action in TreeStructureDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelTreeNodeDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("tree_structure");
			JsonSerializer.Serialize(writer, TreeStructureValue, options);
		}

		writer.WriteEndObject();
	}
}